/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.eventos.beans;

import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.cip.esymons.general.util.Utiles;


/**
 *
 * @author lizardo
 */
public class PruebaController {
    private List<Integer> lista;
    private Integer anioCombo;
    
    /*********************** Constructor de la clase *************************/
    public PruebaController() {
        inicializar();
    }

    /*************************** Sets y Gettters *****************************/
    public List<Integer> getLista() {
        listar();
        return lista;
    }

    public void setLista(List<Integer> lista) {
        this.lista = lista;
    }

    public Integer getAnioCombo() {
        return anioCombo;
    }

    public void setAnioCombo(Integer anioCombo) {
        this.anioCombo = anioCombo;
    }

    /**************************** Metodos ************************************/
    public String inicializar() {
        lista = new ArrayList<Integer>();
        anioCombo = 0;
        return null;
    }

    public String listar() {
        lista = Utiles.aniosParaListarCombo(1991);
        return null;
    }

    public SelectItem[] getComboAnio() {
        try {
            System.out.println("Ingreso 1");
            SelectItem[] selects = null;
            listar();
            selects = new SelectItem[lista.size()];
            int cont = 0;
            for (Integer anio : lista) {
                SelectItem item = new SelectItem(anio, anio.toString());
                selects[cont++] = item;
            }
            return selects;
        } catch (Exception e) {
            System.out.println("Ingreso Error: " + e.getMessage());
            SelectItem[] selects = new SelectItem[1];
            SelectItem item = new SelectItem(null, "No existen tal periodo");
            selects[0] = item;
            return selects;
        }
    }

    public void mostrarMensaje(String resumen, String detalle, FacesMessage.Severity severidad) {
        try {
            FacesMessage fm = new FacesMessage(severidad, resumen, detalle);
            FacesContext.getCurrentInstance().addMessage(fm.toString(), fm);
        } catch (Exception e) {
            FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.getMessage());
            FacesContext.getCurrentInstance().addMessage(fm.toString(), fm);
        }
    }

}
